<?php

namespace app\admin\controller;

use app\admin\model\Config;
use app\common\System;
use think\Request;
use think\Session;

class Index extends Admin
{
    public function index()
    {
        $configModel = new Config();

        if (Request::instance()->isPost()) {
            $data = Request::instance()->post();
            $data['close'] = isset($data['close']) && $data['close'] == 'on' ? 1 : 0;
            $data['qq'] = isset($data['qq']) && $data['qq'] == 'on' ? 1 : 0;
            $data['webRight'] = isset($data['webRight']) && $data['webRight'] == 'on' ? 1 : 0;
            $result = $configModel->main($data);
            if ($result['code'] == '403') {
                $this->error($result['msg']);
            }
            $info = $result['data'];
            $this->success($result['msg']);
        } else {
            $info = $configModel->getInfo(['language' => Session::get('language')]);
        }

        return $this->fetch('index', [
            'info' => $info,
        ]);
    }

    public function system()
    {
        $list = System::langList();

        return $this->fetch('/system/lang', [
            'list' => $list,
            'default' => Session::get('language'),
        ]);
    }
}
